package com.xxl.reflect;

import java.lang.reflect.Constructor;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Demo1107 {
	public static void main(String[] args) {
		Class aclass;
		try {
			aclass = Class.forName("com.xxl.reflect.Student");
//			Method[] methods = aclass.getDeclaredMethods();
//			for (Method method : methods) {
//				System.out.println(method.getName());
//			}
//			Field[] fields = aclass.getDeclaredFields();
//			for (Field field : fields) {
//				System.out.println(field.getName());
//			}
//			Constructor[] constructors = aclass.getDeclaredConstructors();
//			for (Constructor constructor : constructors) {
//				System.out.println(constructor.getName());
//			}
			Constructor constructor = aclass.getDeclaredConstructor(String.class,int.class);
			Object o = constructor.newInstance("Kosaki",17);
			System.out.println(o.toString());
			
			
			Method m = aclass.getDeclaredMethod("setName",String.class);
			Object setname = m.invoke(o,"Chitoge");
			System.out.println(o.toString());
			
			
			Field name = aclass.getDeclaredField("name");
			name.setAccessible(true);
			name.set(o, "Marika");
			Method method = aclass.getDeclaredMethod("toString");
			Object invoke = method.invoke(o);
			System.out.println(invoke);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchFieldException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
